"""Free space radio propagation model

Copyright (C) Sarah Mount, 2008.

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
"""

from __future__ import absolute_import
del absolute_import
from .. import RadioPropagationModel

import math

class FreeSpace(RadioPropagationModel.RadioPropagationModel):
    """Free space propagation model based on work by H.T.Friis.
    Assumes clear line of sight between sender and receiver.
    """
    def __init__(self, power_tx=1.0, gain_tx=1.0, gain_rx=1.0, sysloss=1.0):
        """
	@precondition: sysloss >= 1.0
        @postcondition: self.sysloss >= 1.0

        @type power_tx: float
        @param power_tx: transmitted signal power
        @type gain_tx: float
        @param gain_tx: antenna gain on transmitter
        @type gain_rx: float
        @param gain_rx: antenna gain on receiver
        @type sysloss: float
        @param sysloss: system loss
        """
        
	RadioPropagationModel.RadioPropagationModel.__init__(self)
	self.name = 'Free Space'
        self.power_tx = power_tx
        """ivar: transmitted signal power"""
        self.gain_tx = gain_tx
        """ivar: antenna gain on transmitter"""
        self.gain_rx = gain_rx
        """ivar: antenna gain on receiver"""
	self.sysloss = sysloss
        """ivar: system packet loss"""
        self.wavelen = 809.11 # What the hell is this anyway?
        """ivar: wavelength of tranmitted signal"""
        return
    def getRSSI(self, distance):
        """Return predicted RSSI for packet travelling a given C{distance}.

	@type distance: float
        @param distance: distance packet has travelled
        @rtype: float
        """
        num = self.power_tx * self.gain_tx * self.gain_rx * self.wavelen**2
        denom = 16 * math.pi**2 * distance**2 * self.sysloss
        return num / denom
        

freeSpace = FreeSpace()
